<?php
/*
 * This file is part of EC-CUBE
 *
 * Copyright(c) 2000-2012 LOCKON CO.,LTD. All Rights Reserved.
 *
 * http://www.lockon.co.jp/
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 */

// {{{ requires

require_once CLASS_EX_REALDIR . 'page_extends/LC_Page_Ex.php';
/**
 * 会員登録のページクラス.
 *
 * @package Page
 * @author LOCKON CO.,LTD.
 * @version $Id: LC_Page_Regist.php 21950 2012-07-02 11:42:51Z pineray $
 */
class LC_Page_NewPassWord extends LC_Page_Ex {

    // {{{ properties

    // }}}
    // {{{ functions
	
    /**
     * Page を初期化する.
     *
     * @return void
     */
    function init() {
    	
        parent::init();
        $this->tpl_mainpage = 'regist/newPassWord.tpl';
        $this->tpl_javascript = '$("#mainBody").removeClass("front");';
        $this->tpl_javascript .= ' $("#mainBody").addClass("not-front page-user-register section-user cron-check-processed");';
    }

    /**
     * Page のプロセス.
     *
     * @return void
     */
    function process() {
        parent::process();
        $this->action();
        $this->sendResponse();
    }

    /**
     * Page のAction.
     *
     * @return void
     */
    function action() {

        switch ($this->getMode()) {
            case 'findPassWord':
				//邮件存在性检查
				if($this->mailCheck()){
					//发送修改密码邮件
				
					//转到成功页面

				}else{
					
				}
				
                break;
            default:
                //SC_Utils_Ex::sfDispSiteError(FREE_ERROR_MSG, '', true, '無効なアクセスです。');
                break;
        }


    }

    /**
     * デストラクタ.
     *
     * @return void
     */
    function destroy() {
        parent::destroy();
    }


	/**
	*
	*/
	function mailCheck(){
		
		$mail = $this->getValFromPostOrGet('email');
		
		if(!empty($mail)){
			$mail = strtolower($mail);
			
			$objQuery = SC_Query::getSingletonInstance();
	    	$cnt = $objQuery->count('mst_users', "user_id = ?", array($mail));

			if($cnt == 1){
				return true;
			}else{
				return false;
			}
			
		}else{
			return false;
		}
	}


    /**
	 * 发送注册确认信
	 * Enter description here ...
	 */
	function sendFindpassWordMail() {
		//注册送信
        $objMailText = new SC_SiteView();
        $objMailText->assignobj($this);
        GC_Utils_Ex::gfPrintLog($userId);
        //$link= HTTP_URL.'regist/regist.php?mode=mailconfirm&id='.$this->arrInsertKey[0]['id'];
        $objQuery = SC_Query::getSingletonInstance();
	    $rs1 = $objQuery->select('*','mst_users', "id = ? ", array($userId));
	    $rs2 = $objQuery->select('*','tab_person_users', "id = ? ", array($userId));
	    
	    $masterData = new SC_DB_MasterData();
	    $titleList =$masterData->getMasterData("mst_title");
		
	    
	    $link= HTTP_URL.'index.php';
        $name = '';
        $titleId = $rs2[0]['title_id'];
        if(!empty($titleId) && trim($titleId) != '1'){
        	$name = $titleList[$titleId].' '.$rs2[0]['firstname'];
        }else{
        	$name = $rs2[0]['firstname'].' '.$rs2[0]['lastname'];
        }
		$objMailText->assign('link', $link);
		$objMailText->assign('name', $name);
		$objMailText->assign('Organization', ORGANIZATION_NAME_SIMPLE);
		
		$objMailText->assign('regist_postVal', $this->regist_postVal);
        $toCustomerMail = $objMailText->fetch("mail_templates/customer_regist_mail.tpl");
        $objMail = new SC_SendMail();
		
        //$this->regist_postVal;
        $objMail->setItem(
                              $rs1[0]['mail_add']	//　宛先
                            , ORGANIZATION_NAME_SIMPLE.' welcome' //　サブジェクト
                            , $toCustomerMail					//　本文
                            , ORGANIZATION_MAIL					//　配送元アドレス
                            , ORGANIZATION_NAME_SIMPLE			//　配送元　名前
                            , ORGANIZATION_MAIL					//　reply_to
                            , ORGANIZATION_MAIL					//　return_path
                            , ORGANIZATION_MAIL					//  Errors_to

                                                            );
        $objMail->setTo($rs1[0]['mail_add'], $name);
        $objMail->sendMail();
    }
}
